<template>
    <div class="page">
        <div class="tab">
            <div class="tab-menu">
                <div class="tab-menu-item"
                     v-for="(item,index) in listArr"
                     :class="{'active' : tabCurr==index}"
                     @click="tabFun(index)"
                >{{item.name}}</div>
            </div>
            <div class="tab-body">
                <div class="tab-body-item" v-for="(item,index) in listArr" :class="{'active' : tabCurr==index}">
                    <div class="tab-list" v-if="strategy">
                        <router-link class="tab-list-item"
                                     v-for="(item2,index2) in item.data"
                                     :to="{path:'/city',query:{city_id:item2.city_id,city_name:encodeURI(item2.name)}}"
                        >
                            <div class="tab-list-item-title">{{item2.name}}</div>
                            <img class="tab-list-item-more" src="../assets/city-list-arr.png"></img>
                        </router-link>

                    </div>
                    <!--判断哪个页面跳转过来-->
                    <div class="tab-list" v-if="!strategy">
                        <router-link class="tab-list-item"
                                     v-for="(item2,index2) in item.data"
                                     :to="{path:'/strategy-city',query:{city_id:item2.city_id,city_name:item2.name}}"
                        >
                            <div class="tab-list-item-title">{{item2.name}}</div>
                            <img class="tab-list-item-more" src="../assets/city-list-arr.png"></img>
                        </router-link>

                    </div>
                </div>
            </div>
        </div>
        <div class="h120"></div>
        <TabBar :curr="tabBarCurr"></TabBar>
    </div>
</template>

<script>
    import { Toast } from 'mint-ui';
    import TabBar from "../components/TabBar"
    import config from "../store/config"
    import wxShare from "../store/wxShare"
    export default {
        name: "CityChoose",
        components:{
            TabBar
        },
        data(){
            return{
                tabBarCurr:2,
                tabCurr:0,
                listArr:[],
                strategy:true,
                params:'',
            }
        },
        created(){
            //获取传入的参数
            var param = this.$route.query.strategy;
            this.params = param
//            console.log(param)
            if(this.$route.query.strategy==1){
                this.strategy=false
            }

        },
        methods:{
            tabFun(val){
                this.tabCurr=val;
                this.share();
            },
            getData(){
                this.axios.get('wapcity', {})
                    .then(res => {
                        this.listArr=res.data

                        if (this.$store.state.token) {//分享
                            this.share();
                        }
                    })
                    .catch(err => console.log(err));
            },
            // 分享
            share() {
                wxShare({
                    title: '快帮行', // 分享标题
                    desc: '了解'+this.listArr[this.tabCurr].name+'的当地玩乐。', // 分享描述
                    //link: window.location.href, // 分享链接
                    imgUrl: 'https://c.kuaibangxing.com/ueditor/php/upload/image/20180907/1536299154817944.png', // 分享图标
                    debug: false
                }, function () {//分享成功后的回调函数
                    //Toast({message: '分享成功！', duration: 1500});
                    console.log('分享成功')
                });
            }
        },
        mounted(){
            this.tabCurr=this.$route.query.id || 0;
            this.getData();
        }
    }
</script>

<style lang="scss" scoped>
    @import "../assets/base";
    .page{
        background: $bgcolor1;
        min-height: 100%;
    }
    .h120 {
        height: rpx(150);
        background: $bgcolor1;
    }
    .tab{

        background: $color0;
        &-menu{
            display: flex;
        }
        &-menu-item{
            flex: 1;
            padding:rpx(30) rpx(20);
            text-align: center;
            color: $color5;
            font-size: rpx(40);
            border-bottom: solid $color2 rpx(4) ;
            &.active{
                color: $color3;
                border-bottom: solid $color3 rpx(4) ;
            }
        }

        &-body{
            &-item{
                display: none;
                &.active{
                    display: block;
                }
            }
        }

        //列表
        &-list{
            &-item{
                display: flex;
                align-items: center;
                padding: rpx(30);
                border-bottom: solid 1px $color2;
                &-title{
                    flex: 1;
                    font-size: rpx(34);
                }
                &-more{
                    width: rpx(32);
                    height: rpx(32);
                }
            }
        }

    }


</style>